import {
    defineStore
} from 'pinia';

import { newComments, getReplyComments } from "@/apis/apis.js";


export const useCommentStore = defineStore('comment', {
    state: () => ({
        target: '',//input的placeholder内容
        currPostId: null,//当前帖子id
        currCommentId: null,//当前评论id(当评论子评论时为父评论id)
        isShowInp: false,//控制input框的input
        isActiveReply: 0,//标记有没有回复的行为,有就++
		isDeleteSonComment:0,//标记有没有删除子评论行为，有就++
		currentParentId:null//用于标识被删除的子评论的父评论的id
		
    }),
    actions: {
        handleInp(val) {
            this.isShowInp = val
        },
        setTarget(target, currPostId, currCommentId) {
            this.target = target
            this.currPostId = currPostId
            this.currCommentId = currCommentId
        },
		setCurrentParentId(id){
			this.currentParentId=id
		},
		deleteSonComment(){
			this.isDeleteSonComment++
		},
        async reply(content) {
            const res = await newComments({ postId: this.currPostId, content, parentId: this.currCommentId });
            if (res.status === 200) {
                this.isShowInp = false
                // this.currCommentId = null
                // this.currPostId = null
                this.isActiveReply++
            }
            return res
        },
        getReply(data) {
            return getReplyComments(data)
        }
    }
})